#include <iostream>
#include <string>
using namespace std;

class Solution
{
public:
    static bool backspaceCompare(string s, string t)
    {
        string vs;
        string vt;
        for(char ch : s)
        {
            if(ch != '#')
                vs.push_back(ch);
            else
            {
                if(!vs.empty())
                    vs.pop_back();
            }
        }
        for(char ch : t)
        {
            if(ch != '#')
                vt.push_back(ch);
            else
            {
                if(!vt.empty())
                    vt.pop_back();
            }
        }
        if(vs.size() != vt.size())
            return false;
        for(int i=0; i<vs.size(); i++)
        {
            if(vs[i] != vt[i])
                return false;
        }
        return true;
    }
};